#include "SLineEdit.h"

#include <QMouseEvent>

SLineEdit::SLineEdit(const QString& txt, QWidget* parent /*= nullptr*/)
    : QLineEdit(txt, parent) {}

void SLineEdit::focusInEvent(QFocusEvent* e) { QLineEdit::focusInEvent(e); }

void SLineEdit::mousePressEvent(QMouseEvent* e) {
  bool hasSel = hasSelectedText();

  QLineEdit::mousePressEvent(e);

  int pos = cursorPosition();
  QString text = displayText();
  int len = text.length();
  if (m_selectAllWhenFocus && pos == len && !hasSel &&
      e->button() == Qt::LeftButton) {
    selectAll();
  }

  emit clicked();
}
